﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using TileEditorApplication.TileClasses;

namespace TileEditorApplication
{
    public class Map
    {
        public Size mapSize;
        public Size tileSize;
        public Tile[,] mapMatrix;
        public int[,] tilesetIndex;

        public Map(int width = 10, int height = 10, int tileWidth = 64, int tileHeight = 64)
        {
            mapMatrix = new Tile[width, height];
            tilesetIndex = new int[width, height];
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    mapMatrix[i, j] = new Tile(new Point(-1, -1));
                    tilesetIndex[i, j] = -1;
                }
            }

            mapSize = new Size(width, height);
            tileSize = new Size(tileWidth, tileHeight);
        } 

        public Rectangle GetRect()
        {
            Rectangle rect = new Rectangle(0, 0, mapSize.Width * tileSize.Width, mapSize.Height * tileSize.Height);
            return rect;
        }

        public void ResizeMap(Size newSize)
        {
            Tile[,] temp = new Tile[newSize.Width, newSize.Height];
            int[,] tempIndex = new int[newSize.Width, newSize.Height];

            for (int x = 0; x < newSize.Width; ++x)
            {
                for (int y = 0; y < newSize.Height; ++y)
                {
                    if (x < mapSize.Width && y < mapSize.Height)
                    {
                        temp[x, y] = mapMatrix[x, y];
                        tempIndex[x, y] = tilesetIndex[x, y];
                    }
                    else
                    {
                        temp[x, y] = new Tile(new Point(-1,-1));
                        tempIndex[x, y] = -1;
                    }
                }
            }

            mapSize = newSize;

            mapMatrix = temp;

            tilesetIndex = tempIndex;
        }

    }
}
